/**
*add by lukx 变更保存
*/
const modifySave = {
	buildObject: (attrArr, row, ppmParams, orderPosInfo, user, changeConfig) => {
		let modCount = 0;;
		let attrCount = 0;
		//页面上无字段修改不能保存
		attrArr.forEach((item) => {
			if (item.tableName && item.colId && item.value != '' && item.value != null) {
				if ((item.oldValue && item.oldValue != item.value) || !item.oldValue) {
					if (item.colId != '100012408') {
						modCount++;
					}
				}

			}
			if (item.colId != '100012408') {
				attrCount++;
			}
		});
		if (modCount == 0 && attrCount != 0) {
			alert("页面无修改！")
			return false;
		} else {
			let requestObject = {};
			requestObject.operType = JSON.parse(sessionStorage.getItem("FormModel"))?(JSON.parse(sessionStorage.getItem("FormModel")).custOrderId?'1200':'1000'):'1000';
			requestObject.custId = orderPosInfo.custId;
			requestObject.custOrderId = JSON.parse(sessionStorage.getItem("FormModel"))?JSON.parse(sessionStorage.getItem("FormModel")).custOrderId||'':'';//第一次没有第二次变更到项目保存之前都是有的
			requestObject.custSoNumber = JSON.parse(sessionStorage.getItem("FormModel"))?JSON.parse(sessionStorage.getItem("FormModel")).custSoNumber||'':'';//第一次没有第二次变更到项目保存之前都是有的
			let serviceOfferId = ppmParams.serviceOfferId;
			if (serviceOfferId == '4020100000') {//拆机cust_order_type需要特殊处理
				requestObject.custOrderType = '50200005';
			} else {
				requestObject.custOrderType = ppmParams.modType;//非正常变更50200002,正常变更50200003
			}
			requestObject.custName = orderPosInfo.custName;
			requestObject.createStaff = user.staffId;
			requestObject.createOrgId = user.orgId;
			requestObject.sysSource = "1000";
			requestObject.remark = "";
			requestObject.acceptRegionId = user.regionId;
			requestObject.acceptLanId = user.regionId;
			requestObject.channelId = '10';
			requestObject.orderSource = '1000';
			if (ppmParams.modType == '50200003') {//正常变更订单起需求单起
				requestObject.handleStateCd = changeConfig.selectBill;
			}
			requestObject.orderItemModifys = modifySave.getOrderItemModifys(attrArr, row, ppmParams, orderPosInfo, user);
			return requestObject;
		}

	},
	getOrderItemModifys: (attrArr, row, ppmParams, orderPosInfo, user) => {

		let orderItemModifyArr = [];
		//let orderItemArr=orderItems.split(",");"orderItems 前页面列表会返回的orderItemId  多条的话用逗号分隔"
		//for (let  item of orderItems){
		let orderItems = row.orderItemId;//取前面列表orderItermId，多选的时候用,隔开
		let offerInstIds = row.offerInstId
		let orderItemModify = {};
		orderItemModify.serviceOfferId = ppmParams.serviceOfferId;
		if (ppmParams.modType == '50200002') {
			orderItemModify.orderItemId = orderItems;//非正常变更的需要  前页面列表会带回的orderItemId  多条的话用逗号分隔
		} else {
			orderItemModify.offerInstIds = offerInstIds;//正常变更的需要 前页面列表会带回的offerInstId  多条的话用逗号分隔

		}
		attrArr.forEach((item) => {
			if (item.colId == '100012408') {
				orderItemModify.modReson = item.value;//变更原因
				orderItemModify.modComment = item.value;//变更原因
			}
		});
		orderItemModify.modOldOrderNbr = row.custSoNumber;//前页面列表的流水号带入
		orderItemModify.modTypeFlag = "2";
		orderItemModify.orderItemFiles = modifySave.getOrderItemFiles(attrArr);
		orderItemModify.orderItemAttrModifys = modifySave.getOrderItemAttrModifys(attrArr);
		orderItemModifyArr.ordProdInstAttachs = modifySave.getOrdProdInstAttachs(attrArr);
		orderItemModifyArr.push(orderItemModify)
		//}
		return orderItemModifyArr;
	},
	getOrderItemAttrModifys: (attrArr) => {
		let orderItemAttrModifyArr = [];
		attrArr.forEach((item) => {
			let obj = {};
			if (item.tableName && item.colId && item.value != '' && item.value != null) {
				if ((item.oldValue && item.oldValue != item.value) || !item.oldValue) {
					let attrid = '';
					if (item.id.split('-').length > 1) {
						attrid = item.id.split('-')[1];
					} else {
						attrid = item.id;
					}
					obj.attrId = attrid;
					obj.attrValue = item.value;
					obj.attrCd = item.fieldId;
					if (item.attrRoleCd) {
						obj.roleCd = item.attrRoleCd;
					} else {
						obj.roleCd = '0';
					}
					orderItemAttrModifyArr.push(obj)
				}
			}
		});
		return orderItemAttrModifyArr;
	},
	getOrderItemFiles: (attrArr) => {
		let orderItemFileArr = [];
		attrArr.forEach((item) => {
			let obj = {};
			if (item.tableName == 'ORDER_ITEM_FILE' && item.value != '' && item.value != null) {
				if ((item.oldValue && item.oldValue != item.value) || !item.oldValue) {

					obj.fileName = item.fileName;
					obj.fileTypeCd = item.fileTypeCd;
					obj.filePath = item.filePath;
					obj.fileDesc = item.fileDesc;
					obj.custItemFileFlag = '1';
					orderItemFileArr.push(obj);
				}
			}
		});
		return orderItemFileArr;
	},
	getOrdProdInstAttachs: (attrArr) => {
		let ordProdInstAttachArr = [];
		attrArr.forEach((item) => {
			let obj = {};
			if (item.tableName == 'PROD_INST_ATTCH' && item.value != '' && item.value != null) {
				if ((item.oldValue && item.oldValue != item.value) || !item.oldValue) {
					obj.procProdInstAttrId = item.procProdInstAttrId;
					obj.attrId = item.attrId;
					obj.attrValue = item.attrValue;
					obj.attrCd = item.attrCd;
					obj.groupId = '1';
					orderItemFileArr.push(obj);
				}
			}
		});
		return ordProdInstAttachArr;
	}
}

export default modifySave;
